#include <stdio.h>
#include <stdlib.h>

#define N  (1<<24)

void
panic (char *m)
{
  fprintf (stderr, "%s\n", m);
  exit (0);
}

int
main (int argc, char *argv[])
{
  unsigned int n, i, count = 0, *p;

  if (argc > 1)
    n = atoi (argv[1]);
  else
    n = N;

  if (posix_memalign ((void **) &p, 16, n * sizeof (unsigned int)) == -1)
    panic ("malloc");

  /* Random init the vector */
  for (i = 0; i < n; i++)
    p[i] = rand ();

  /* Accumulates popcount for all elements */
  for (i = 0; i < n; i++)
    count += __builtin_popcount (p[i]);

  printf ("%d\n", count);
}
